package com.it.aop.demoaop01.service.impl;

import com.it.aop.demoaop01.dao.DateDao;
import com.it.aop.demoaop01.dao.UserDao;
import com.it.aop.demoaop01.pojo.User;
import com.it.aop.demoaop01.service.Doservice;
import com.it.aop.demoaop01.utils.ConnectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @Author: xiaoqiang
 * @Description:
 * @Date: 2021/6/9
 * @Version: 1.0
 */
@Service
public class DoserviceImpl implements Doservice {

    @Autowired
    private DateDao dateDao;

    @Autowired
    private UserDao userDao;

    public DateDao getDateDao() {
        return dateDao;
    }

    public void setDateDao(DateDao dateDao) {
        System.out.println("执行setDateDao");
        this.dateDao = dateDao;
    }

    @Override
    public void f1() {

        Connection connection = ConnectionUtil.getConnection();
        try {
            connection.setAutoCommit(false);
            User user = new User(1, "dddd");
            dateDao.addUser(user);
            int a = 10 / 0;
            String date = userDao.getDate();
            connection.commit();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

}
